package com.ruoyi.resume.controller;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.servlet.http.HttpServletResponse;


import com.ruoyi.resume.domain.vo.CorporationVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.resume.domain.CvSkill;
import com.ruoyi.resume.service.ICvSkillService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 专项技能Controller
 * 
 * @author ruoyi
 * @date 2024-05-31
 */
@RestController
@RequestMapping("/skill")
public class CvSkillController extends BaseController
{
    @Autowired
    private ICvSkillService cvSkillService;

    /**
     * 查询专项技能列表
     */
    @RequiresPermissions("resume:skill:list")
    @GetMapping("/list")
    public TableDataInfo list(CvSkill cvSkill)
    {
        startPage();
        List<CvSkill> list = cvSkillService.selectCvSkillList(cvSkill);
        return getDataTable(list);
    }

    /**
     * 导出专项技能列表
     */
    @RequiresPermissions("resume:skill:export")
    @Log(title = "专项技能", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CvSkill cvSkill)
    {
        List<CvSkill> list = cvSkillService.selectCvSkillList(cvSkill);
        ExcelUtil<CvSkill> util = new ExcelUtil<CvSkill>(CvSkill.class);
        util.exportExcel(response, list, "专项技能数据");
    }

    /**
     * 获取专项技能详细信息
     */
    @RequiresPermissions("resume:skill:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cvSkillService.selectCvSkillById(id));
    }

    /**
     * 新增专项技能
     */
    @RequiresPermissions("resume:skill:add")
    @Log(title = "专项技能", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CvSkill cvSkill)
    {
        return toAjax(cvSkillService.insertCvSkill(cvSkill));
    }

    /**
     * 修改专项技能
     */
    @RequiresPermissions("resume:skill:edit")
    @Log(title = "专项技能", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CvSkill cvSkill)
    {
        return toAjax(cvSkillService.updateCvSkill(cvSkill));
    }

    /**
     * 删除专项技能
     */
    @RequiresPermissions("resume:skill:remove")
    @Log(title = "专项技能", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cvSkillService.deleteCvSkillByIds(ids));
    }



    @PostMapping("/findSkill")
    public Set<CorporationVo> findSkill()
    {
        List<CvSkill> corporations = cvSkillService.findSkill();
        Set<CorporationVo> list = new HashSet<>();
        for (CvSkill post : corporations) {

            if (post.getSkillAfter()!=null){

                list.add(new CorporationVo( post.getSkillAfter()));
            }
        }
        return list;
    }
}
